/**
 * 
 */
package leetCode;

/**
 * @author zhong
 *
 */
public class SumofRootToLeafBinaryNumbers {
	public int sumRootToLeaf(TreeNode root) {
		return help(root, 0);
	}

	int mod = 1000000007;

	private int help(TreeNode root, int i) {
		if (root == null) {
			return 0;
		}
		int newVal = (i * 2 % mod + root.val) % mod;
		if (root.left == null && root.right == null) {
			return newVal;
		}

		return (help(root.left, newVal) + help(root.right, newVal)) % mod;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
